package com.power.thread.framework.lock;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @description:
 * @author: jiangnan
 * @time: 2021/6/1 2:12 下午
 */
public class ReentreLock {
    public static void main(String[] args) {

        ReentrantLock reentrantLock = new ReentrantLock();
    }


    public class Widget {
        public synchronized void doSomething() {
            System.out.println("方法1执行...");
            doOthers();
        }

        public synchronized void doOthers() {
            System.out.println("方法2执行...");
        }
    }
   /* protected final int tryAcquireShared(int unused) {
        Thread current = Thread.currentThread();
        int c = getState();
        if (exclusiveCount(c) != 0 &&
                getExclusiveOwnerThread() != current)
            return -1;                                   // 如果其他线程已经获取了写锁，则当前线程获取读锁失败，进入等待状态
        int r = sharedCount(c);
        if (!readerShouldBlock() &&
                r < MAX_COUNT &&
                compareAndSetState(c, c + SHARED_UNIT)) {
            if (r == 0) {
                firstReader = current;
                firstReaderHoldCount = 1;
            } else if (firstReader == current) {
                firstReaderHoldCount++;
            } else {
                HoldCounter rh = cachedHoldCounter;
                if (rh == null || rh.tid != getThreadId(current))
                    cachedHoldCounter = rh = readHolds.get();
                else if (rh.count == 0)
                    readHolds.set(rh);
                rh.count++;
            }
            return 1;
        }
        return fullTryAcquireShared(current);
    }*/
}
